import React, {PureComponent} from 'react';
import styles from './index.less';
import {Link} from 'dva/router';
import {Table, Alert, Badge, Switch, Icon, InputNumber, Tooltip, Popconfirm,Button}  from 'antd';
import {powerControl} from '../../../utils/powerControl';
const AuthButton = powerControl(Button);

class ShippingTempletAttr extends PureComponent {

    state = {
        selectedRowKeys: [],
        totalCallNo: 0,
    };
    componentWillReceiveProps(nextProps) {
        if (nextProps.selectedRows.length === 0) {
            this.setState({
                selectedRowKeys: [],
                totalCallNo: 0,
            });
        }
    }
    handleEditRow = (record, pagination) => {
        this.props.onEditRow(record, pagination);
    }

    handleTableChange = (pagination, filters, sorter) => {
        this.props.onChange(pagination, filters, sorter);
    }

    handleDelRow = (shipping_templet_attr_id, pagination) => {
        this.props.onDelRow(shipping_templet_attr_id, pagination);
    }

    render(){
          const {selectedRowKeys, totalCallNo} = this.state;
          const {data: {list, pagination}, loading} = this.props;
        const columns = [
            {
                title: '配送方式', dataIndex: 'shipping_name',
                render: (val, record) => {
                    return <Tooltip placement="right" title={val}>
                        <span><font style={{color:'black'}}>快递名称：</font>{val}</span><br/>
                        <Button onClick={()=>this.handleEditRow(record, pagination)}>添加地区</Button>

                    </Tooltip>
                }
            }, {
                title: '区域名称',
                dataIndex: 'shipping_area_name',
                render: (val, record) => {
                    return <Tooltip placement="right" title={val}>
                        <span>{val}</span>
                    </Tooltip>

                }
            }, {
                title: '所辖地区', dataIndex: 'shipping_area_ids',
                render: (val, record) => {
                    return <Tooltip placement="right" title={val}>
                        <span>{val}</span>
                    </Tooltip>
                }
            }
            , {
                title: '操作',

                render: (val, record) => {
                    return <Tooltip placement="right">
                        <AuthButton auth="shipping.edit" ghost  className={styles.btn} size="small" onClick={() => this.handleEditRow(record, pagination)}>编辑</AuthButton>
                        <span className={styles.splitLine}/>
                        <Popconfirm title="是否确定删除?" onConfirm={() => this.handleDelRow(record.shipping_templet_attr_id, pagination)} >
                            <AuthButton auth="shipping.delete" ghost  className={styles.btn} size="small">删除</AuthButton>
                        </Popconfirm>
                    </Tooltip>

                }
            }
        ];

        // const rowSelection = {
        //     onChange: (selectedRowKeys, selectedRows) => {
        //         console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
        //     },
        //     onSelect: (record, selected, selectedRows) => {
        //         console.log(record, selected, selectedRows);
        //     },
        //     onSelectAll: (selected, selectedRows, changeRows) => {
        //         console.log(selected, selectedRows, changeRows);
        //     },
        // };
        const paginationProps = {
            showSizeChanger: true,
            showQuickJumper: true,
            ...pagination,
        };
        return (
            <div className={styles.standardTable}>
                <Table
                loading={loading}
                rowKey={record => record.id}
                // rowSelection={rowSelection}
                dataSource={list}
                columns={columns}
                pagination={paginationProps}
                onChange={this.handleTableChange}
                scroll={{ }}
            />
            </div>
        )

    }
}
export default ShippingTempletAttr;

